package com.mycompany.app.hr.eleave.service.leavepolicy.impl;

import org.apache.commons.lang.time.DurationFormatUtils;

import com.mycompany.app.hr.eleave.exception.LeaveValidationException;
import com.mycompany.app.hr.eleave.model.LeaveApplication;
import com.mycompany.app.hr.eleave.service.leavepolicy.ILeavePolicyCheck;
import com.mycompany.app.hr.pa.model.Employee;

/**
 * 婚假
 * 
 * Male>=25    Female>=23
 First marriage <=13 days
 Second marriage <=3 days
 
 //Male <25  Female <23  <=3days
 * @author Shawn.guo
 *
 */
public class MarriageLeaveCheck implements ILeavePolicyCheck {

    public void check(Employee employee, LeaveApplication app)
            throws LeaveValidationException {

        Integer marriageAge = Integer.valueOf(DurationFormatUtils.formatPeriod(
                employee.getBasicInfo().getBirthday().getTime(), app
                        .getPeriod().getFromDate().getTime(), "y"));
        Integer leaveCalendarDays = app.calculateCalendarDays();
        String sex = employee.getBasicInfo().getSex();

        if (("M".equals(sex) && marriageAge >= 25 && leaveCalendarDays > 13)
                || ("F".equals(sex) && marriageAge >= 25 && leaveCalendarDays > 13))
            throw new LeaveValidationException(
                    LeaveValidationException.MARRIAGE);
//        
//        if (hasMarriageLeaveBefore(app) && days > 3)

    }

}
